package org.zeroes.common_prelude;

public class Rect {
	public float left ;
	public float top ;
	public float right;
	public float bottom;
	public String id="";

	public Rect(float left,float top,float right,float bottom){
		this.set(left, top, right, bottom);
	}
	
	public Rect(float left,float top,float right,float bottom,String _id){
		this.set(left, top, right, bottom);
		this.id=_id;
	}
	
	
	public void set(float  left,float top,float right,float bottom){
		this.left = left;
		this.top = top;
		this.right = right;
		this.bottom = bottom;
	}
	
	public float width(){
		return this.right - this.left;
	}
	
	public float height(){
		return this.bottom - this.top;
	}
	
	public boolean intersects_rect(Rect rc){
		return !(rc.right < this.left || rc.bottom < this.top || rc.left > this.right || rc.top > this.bottom);
	}
	
	public boolean contains_pt(int x,int y){
		return (x >= this.left && x <= this.right) && (y >= this.top && y <= this.bottom);
	}
	
	public  Rect offset(int px, int py){
		this.left += px;
		this.top += py;
		this.right += px;
		this.bottom += py;
		return this;
	}
}
